(function () {
    'use strict';

    var app = angular.module('CsopApp', ['CsopApp.Controllers', 'CsopApp.Services', 'CsopApp.Directives',
        'CsopApp.UiRouterStates',
        'ngRoute', 'ui.router', 'ngAnimate', 'ui.bootstrap', 'ngResource'
    ]);

    app.run(['$rootScope', 'loginInfo',
        function ($rootScope, loginInfo) {
            $rootScope.loginInfo = loginInfo;
            $rootScope.status = {};
            $rootScope.status.isUserOpen = false;
        }
    ]);

    app.config(['$httpProvider',
        function ($httpProvider) {
            $httpProvider.defaults.useXDomain = true;
            delete $httpProvider.defaults.headers.common['X-Requested-With'];
        }
    ]);

    //app.config(['$routeProvider',
    //    function ($routeProvider) {
    //        $routeProvider
    //            .when('/', {
    //                controller: 'LoginController',
    //                templateUrl: 'views/login.html'
    //            })
    //            .when('/Welcome', {
    //                controller: 'WelcomeController',
    //                templateUrl: 'views/welcome.html'
    //            })
    //            .when('/AngularIntro', {
    //                controller: 'AngularIntroController',
    //                templateUrl: 'views/angularIntro.html'
    //            })
    //            .when('/login', {
    //                controller: 'LoginController',
    //                templateUrl: 'views/login.html'
    //            })
    //            .otherwise({
    //                redirectTo: '/'
    //            });
    //    }
    //]);

    app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function ($stateProvider, $urlRouterProvider, $locationProvider) {

            $urlRouterProvider.when('', '/login');
            $urlRouterProvider.otherwise('/login');

            $stateProvider
                .state('Login', {
                    url: '/login',
                    templateUrl: 'views/login.html',
                    controller: 'LoginController'
                })
                .state('Home', {
                    abstract: true,
                    url: '/home',
                    templateUrl: 'views/home.html',
                    controller: 'HomeController'
                })
                .state('Home.Desktop', {
                    url: '/desktop',
                    resolve: {
                        resolveModules: function (moduleService) {
                            return moduleService.getModules();
                        }
                    },
                    templateUrl: 'views/desktop.html',
                    controller: 'DesktopController'
                });
            // $locationProvider.html5Mode(true);
        }
    ]);
})();